관련 동영상: https://youtu.be/NjPbNlRcjM4
사이트 별로 비밀번호를 생성하는 프로그램을 작성하라.
naver
)출력 예시:
http://www.naver.com → nav51!
http://www.daum.net → dau40!
http://www.google.com → goo61!
http://www.youtube.com → you71!
다음 문자열 처리 함수를 활용한다:
string.index(sub[, start[, end]])
: 특정 문자의 위치 찾기string.count(sub[, start[, end]])
: 특정 문자의 개수 계산콜론 연산자(:) 활용 예:
a = "안녕하세요. 반갑습니다."
print(a[0:4]) # '안녕하세'
print(a[:]) # 전체 문자열 출력
print(a[:5]) # 처음 5글자 출력
print(a[6:]) # 6번째 이후 출력
비밀번호 생성 코드:
url = "http://www.naver.com"
index_dot1 = url.index(".")
index_dot2 = url.index(".", index_dot1 + 1)
# 규칙 1 적용
myStr = url[index_dot1+1:index_dot2]
# 규칙 2 적용
password = myStr[:3] + str(len(myStr)) + str(myStr.count("e")) + "!"
print("{0}의 비밀번호는 {1}입니다.".format(url, password))
Note: input()
함수를 사용하여 사용자 입력을 받을 수 있다.
학번을 활용한 비밀번호 생성 프로그램을 작성하라.
출력 예시:
http://www.naver.com → nav1234!
http://www.daum.net → dau1234!
http://www.google.com → goo1234!
http://www.youtube.com → you1234!
비밀번호 생성 코드:
student_id = "202301234"
url = "http://www.naver.com"
index_dot1 = url.index(".")
index_dot2 = url.index(".", index_dot1 + 1)
myStr = url[index_dot1+1:index_dot2]
password = myStr[:3] + student_id[-4:] + "!"
print("{}의 비밀번호는 {}입니다.".format(url, password))